﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Huayuan.Manage.Common;
using Huayuan.Manage.Areas.Passport.Models;
using Hyt.Passport.QueryModels;
using Hyt.Passport;
using Hyt.Web.Mvc;
using Hyt.Core;
using Hyt.Passport.Models;

namespace Huayuan.Manage.Areas.Passport.Controllers
{
    public class PositionManageController : BaseController
    {

        #region 列表
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Query()
        {
            return View();
        }

        public ActionResult List()
        {
            return View();
        }

        [HttpPost]
        public JsonResult ListData(PositionQueryModel qo)
        {
            qo.QueryOption.Includes.Add("DepartMent");
            using (var ufw = new WebUnitOfWork())
            {
                var result = ufw.ServiceCenter.GetPositions(qo);
                var data = new
                {
                    page = result.PageIndex,
                    total = result.Total,
                    rows = from row in result select new { id = row.Id, cell = new String[] { row.Name, row.Department.Name } }

                };
                ufw.Commit();
                return new JsonResult { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }

        }
        #endregion


        #region 添加
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public JsonResult Create(Position model)
        {
            using (var ufw = new WebUnitOfWork())
            {
                ufw.ServiceCenter.CreatePosition(model);
                ufw.Commit();
                return Const.JsonSuccess;
            }

        }
        #endregion


        #region 删除
        public JsonResult Delete(Guid[] id)
        {
            using (var ufw = new WebUnitOfWork())
            {
                ufw.ServiceCenter.DeletePositions(id);
                ufw.Commit();
                return Const.JsonSuccess;
            }
        }
        #endregion


        #region 修改
        public ActionResult Modify(Guid id)
        {
            using (var ufw = new WebUnitOfWork())
            {
                var dprt = ufw.ServiceCenter.GetPositionById(id);
                Guard.Check(dprt).IfIsNull().ThrowNoExisted("职位");
                ufw.Commit();
                return View(dprt);
            }
        }

        [HttpPost]
        public JsonResult Modify(Department model)
        {
            using (var ufw = new WebUnitOfWork())
            {
                //ufw.ServiceCenter.(model);
                //ufw.Commit();
                //NotifyOpenner(Common.JS.Intents.action_dataischange);
                return Const.JsonSuccess;
            }
        }

        #endregion
        
    }
}
